﻿using GoodFit.BLL.Function;
using GoodFit.BLL.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Http;

namespace GoodFit.BLL.Repository
{
    public class TaskRepository : ITaskRepository
    {
        private List<MTask> taskList = new List<MTask>();
        public TaskRepository()
        {
            taskList.Add(new MTask
            {
                Id = 1,
                AreaPath = "a",
                AssignedTo = "b",
                CompletedWork = 4,
                CreatedBy = "aa",
                CreatedDate = DateTime.Now,
                InterationPath = "c",
                OriginalEstimate = 4,
                Priority = "2",
                ProjectFriendName = "aa",
                ProjectName = "aaa",
                State = "aaad"
            });
        }
        public IEnumerable<MTask> GetAllTask()
        {
            return taskList;
        }
        public string AddTask(MTask task)
        {
            taskList.Add(task);
            return "Task added";
        }
        public MTask GetMTaskById(int id)
        {
            var task = taskList.FirstOrDefault<MTask>((p) => p.Id == id);
            if (task == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }
            return task;
        }
        public void DeleteTask(int id)
        {
            var task = taskList.FirstOrDefault<MTask>((p) => p.Id == id);

            if (task == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            taskList.Remove(task);
        }
    }
}